﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using Groove.Core.Player;
using Groove.Wpf.Annotations;

namespace Groove.Wpf
{
    public class WindowViewModel : INotifyPropertyChanged
    {
        private PlayMode _playMode = PlayMode.ListCycle;

        public PlayMode PlayMode
        {
            get => _playMode;
            set
            {
                _playMode = value;
                OnPropertyChanged(nameof(PlayMode));
            }
        }

        private int _volumn = 100;

        public int Volumn
        {
            get => _volumn;
            set
            {
                _volumn = value;
                OnPropertyChanged(nameof(Volumn));
                IsMute = _volumn == 0;
            }
        }

        private bool _isMute;

        public bool IsMute
        {
            get => _isMute;
            set
            {
                _isMute = value;
                OnPropertyChanged(nameof(IsMute));
            }
        }

        private string _title;
        public string Title
        {
            get => _title;
            set
            {
                _title = value;
                OnPropertyChanged(nameof(Title));
            }
        }

        private string _artistAndAlbum;

        public string ArtistAndAlbum
        {
            get => _artistAndAlbum;
            set
            {
                _artistAndAlbum = value;
                OnPropertyChanged(nameof(ArtistAndAlbum));
            }
        }

        private ImageSource _albumCover;

        public ImageSource AlbumCover
        {
            get => _albumCover;
            set
            {
                _albumCover = value;
                OnPropertyChanged(nameof(AlbumCover));
            }
        }

        private string _currentTimeStr = "00:00";

        public string CurrentTimeStr
        {
            get => _currentTimeStr;
            set
            {
                _currentTimeStr = value;
                OnPropertyChanged(nameof(CurrentTimeStr));
            }
        }

        private string _leftTimeStr = "00:00";

        public string LeftTimeStr
        {
            get => _leftTimeStr;
            set
            {
                _leftTimeStr = value;
                OnPropertyChanged(nameof(LeftTimeStr));
            }
        }

        private int _mediaTimeMs=100;

        public int MediaTimeMs
        {
            get => _mediaTimeMs;
            set
            {
                _mediaTimeMs = value;
                OnPropertyChanged(nameof(MediaTimeMs));
            }
        }

        private int _currentTimeMs;

        public int CurrentTimeMs
        {
            get => _currentTimeMs;
            set
            {
                _currentTimeMs = value;
                OnPropertyChanged(nameof(CurrentTimeMs));
            }
        }

        private bool _isPlaying;

        public bool IsPlaying
        {
            get => _isPlaying;
            set
            {
                _isPlaying = value;
                OnPropertyChanged(nameof(IsPlaying));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}